﻿// ———————————————————————–
// <copyright file="TriageCountType.cs" company="The MITRE Corporation">
//    Copyright (c) 2010 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–

/////////////////////////////////////////////////////////////////////////////////////////////////
// TriageCountType.cs - Library Class for the HAVE Message, TriageCount subelement type
// Project: IC.NET - HAVE Library
//
// Language:    C#, .NET 4.0
// Platform:     Windows XP, VS 2010
// Author:      Frank Duff MITRE Rome

/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2010 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)

using System;
using System.ComponentModel;
using System.Xml;
using System.Xml.Serialization;

namespace EDXLSharp.EDXLHAVELib
{
  /// <summary>
  /// The container for all component parts of the TriageCount sub-element of the HAVE message 
  /// </summary>
  [Serializable]
  public partial class TriageCountType : IHAVEComposableObject
  {
    #region Private Member Variables

    /// <summary>
    /// CONDITIONAL 
    /// The name of a certified list maintained by the Community of Interest (COI) for the val referenced. The list identifies the triage codes used by the particular community. 
    /// 1. Hospital element MAY contain a TriageCodeListURN element as specified in the schema, but MUST NOT contain more than one such element.
    /// 2. If a TriageCodeListURN> element is present within a Hospital element, it MUST precede the first TriageCode element within that Hospital element.
    /// 3. If a TriageCodeListURN> element is present within a Hospital element and is not empty, then the values of all the TriageCodeValue elements within that Hospital element MUST be interpreted according to the URN in the TriageCodeListURN element.
    /// 4. If a TriageCodeListURN> element is not present within a Hospital element or it is present but empty, then the values of all the TriageCodeValue elements within that Hospital element MUST be interpreted according to the following URN:
    /// urn:oasis:names:tc:emergency:have:1.1:triagecolorcode
    /// which identifies the code list specified in the data dictionary entry for the element TriageCodeValue.
    /// </summary>
    private Uri triageCodeListURN;

    /// <summary>
    /// OPTIONAL, May use Multiple
    /// The container element to specify the triage values and their quantity. 
    /// 1. Multiple instances of the TriageCodeValue MAY occur with a single TriageCodeListURN
    /// 2. Each TriageCodeValue and its associated TriageCountQuantity MUST be enclosed in TriageCode
    /// </summary>
    private TriageCodeType triageCode;
    #endregion

    #region Constructors
    /// <summary>
    /// Initializes a new instance of the TriageCountType class Default Ctor - Initializes Lists (if applicable)
    /// </summary>
    public TriageCountType()
    {
    }
    #endregion

    #region Public Accessors
    /// <summary>
    /// Gets or sets
    /// CONDITIONAL 
    /// The name of a certified list maintained by the Community of Interest (COI) for the val referenced. The list identifies the triage codes used by the particular community. 
    /// 1. Hospital element MAY contain a TriageCodeListURN element as specified in the schema, but MUST NOT contain more than one such element.
    /// 2. If a TriageCodeListURN> element is present within a Hospital element, it MUST precede the first TriageCode element within that Hospital element.
    /// 3. If a TriageCodeListURN> element is present within a Hospital element and is not empty, then the values of all the TriageCodeValue elements within that Hospital element MUST be interpreted according to the URN in the TriageCodeListURN element.
    /// 4. If a TriageCodeListURN> element is not present within a Hospital element or it is present but empty, then the values of all the TriageCodeValue elements within that Hospital element MUST be interpreted according to the following URN:
    /// urn:oasis:names:tc:emergency:have:1.1:triagecolorcode
    /// which identifies the code list specified in the data dictionary entry for the element TriageCodeValue.
    /// </summary>
    [XmlIgnore]
    public Uri TriageCodeListURN
    {
        get { return this.triageCodeListURN; }
        set { this.triageCodeListURN = value; }
    }

    /// <summary>
    /// Gets or sets
    /// The Serializable string version of the triagecodeListURN
    /// </summary>
    [XmlAttribute("triageCodeListURN")]
    [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
    public string TriageCodeListURNString
    {
        get { return this.triageCodeListURN == null ? null : this.triageCodeListURN.ToString(); }
        set { this.triageCodeListURN = value == null ? null : new Uri(value); }
    }

    /// <summary>
    /// Gets or sets
    /// OPTIONAL, May use Multiple
    /// The container element to specify the triage values and their quantity. 
    /// 1. Multiple instances of the TriageCodeValue MAY occur with a single TriageCodeListURN
    /// 2. Each TriageCodeValue and its associated TriageCountQuantity MUST be enclosed in TriageCode
    /// </summary>
    public TriageCodeType TriageCode
    {
      get { return this.triageCode; }
      set { this.triageCode = value; }
    }
    #endregion

    #region Internal Member Functions
    /// <summary>
    /// Writes This Object to an Existing XML Document
    /// </summary>
    /// <param name="xwriter">Pointer to the XMLWriter Writing the Document</param>
    internal override void WriteXML(XmlWriter xwriter)
    {
      this.Validate();

      if (this.triageCodeListURN != null)
      {
        xwriter.WriteElementString("TriageCodeListURN", this.triageCodeListURN.ToString());
      }

      xwriter.WriteStartElement("TriageCode");
      if (this.triageCode != null)
      {
        this.triageCode.WriteXML(xwriter);
      }

      xwriter.WriteEndElement();
    }

    /// <summary>
    /// Reads an XML Object From An Existing DOM
    /// </summary>
    /// <param name="rootnode">Node Containing the root Object element</param>
    internal override void ReadXML(XmlNode rootnode)
    {
      foreach (XmlNode node in rootnode.ChildNodes)
      {
        if (String.IsNullOrEmpty(node.InnerText))
        {
          continue;
        }

        switch (node.LocalName)
        {
          case "TriageCodeListURN":
            this.triageCodeListURN = new Uri(node.InnerText);
            break;
          case "TriageCode":
            this.triageCode = new TriageCodeType();
            this.triageCode.ReadXML(node);
            break;
          case "#comment":
            break;
          default:
            throw new ArgumentException("Unexpected node name: " + node.Name + " in TriageCountType");
        }
      }

      this.Validate();
    }

    #endregion

    #region Protected Member Functions
    /// <summary>
    /// Checks This Object For Required Values and Conformance
    /// </summary>
    protected override void Validate()
    {
    }
    #endregion
  }
}
